﻿using BattleFury.Lib.Graphics;
using BattleFury.Lib.Tiles.Data;
using BattleFury.Tiles;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace BattleFury.Lib.Tiles
{
	public class Tile
		: BaseTile, ITile
	{
		public Tileset Tileset { get; set; }
		public string TilesetAssetName { get; set; }
		public int Index { get; set; }
        //public Vector2 Size { get; set; }
		public Color Tint { get; set; }
        //public Vector2 Position { get; set; }
        //public bool IsVisible { get; set; }
		public Camera Camera { get; set; }

		public Tile()
		{
			Tint = Color.White;
			IsVisible = true;
		}

		public void Draw(SpriteBatch spriteBatch)
		{
			if (!IsVisible) return;
			spriteBatch.Draw(Tileset.Texture, Position, Tileset[Index], Tint);
		}

		public static Tile LoadFrom(Texture2D tileset, Vector2 tileSize, TileData data)
		{
			var ret = new Tile()
			{
				Tileset = new Tileset(tileset, tileSize),
				Index = data.Index,
				Size = tileSize,
				Position = new Vector2(data.X * tileSize.X, data.Y * tileSize.Y)
			};

			return ret;
		}
	}
}